package edu.gdkm.dao;

import edu.gdkm.pojo.Student;
import org.apache.ibatis.annotations.*;
import java.util.List;

public interface StudentDAO {
    // 增加学生信息
    @Insert("INSERT INTO student_info(user_id, real_name, gender, birthday, id_card, " +
            "university, major, education, graduation_time, political_status, hometown, " +
            "current_city, job_intention, job_type, salary_expectation, self_introduction, " +
            "create_time, update_time) " +
            "VALUES(#{user.id}, #{realName}, #{gender}, #{birthday}, #{idCard}, " +
            "#{university}, #{major}, #{education}, #{graduationTime}, #{politicalStatus}, #{hometown}, " +
            "#{currentCity}, #{jobIntention}, #{jobType}, #{salaryExpectation}, #{selfIntroduction}, " +
            "#{createTime}, #{updateTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Student student);

    // 删除学生信息
    @Delete("DELETE FROM student_info WHERE id = #{id}")
    int deleteById(Long id);

    // 更新学生信息
    @Update("UPDATE student_info SET user_id = #{user.id}, real_name = #{realName}, " +
            "gender = #{gender}, birthday = #{birthday}, id_card = #{idCard}, " +
            "university = #{university}, major = #{major}, education = #{education}, " +
            "graduation_time = #{graduationTime}, political_status = #{politicalStatus}, " +
            "hometown = #{hometown}, current_city = #{currentCity}, job_intention = #{jobIntention}, " +
            "job_type = #{jobType}, salary_expectation = #{salaryExpectation}, " +
            "self_introduction = #{selfIntroduction}, update_time = #{updateTime} WHERE id = #{id}")
    int update(Student student);

    // 查询所有学生信息
    @Select("SELECT id, user_id, real_name, gender, birthday, id_card, university, major, " +
            "education, graduation_time, political_status, hometown, current_city, " +
            "job_intention, job_type, salary_expectation, self_introduction, create_time, update_time " +
            "FROM student_info")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "user", column = "user_id",
                    one = @One(select = "edu.gdkm.dao.UserDAO.selectById")),
            @Result(property = "realName", column = "real_name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "idCard", column = "id_card"),
            @Result(property = "university", column = "university"),
            @Result(property = "major", column = "major"),
            @Result(property = "education", column = "education"),
            @Result(property = "graduationTime", column = "graduation_time"),
            @Result(property = "politicalStatus", column = "political_status"),
            @Result(property = "hometown", column = "hometown"),
            @Result(property = "currentCity", column = "current_city"),
            @Result(property = "jobIntention", column = "job_intention"),
            @Result(property = "jobType", column = "job_type"),
            @Result(property = "salaryExpectation", column = "salary_expectation"),
            @Result(property = "selfIntroduction", column = "self_introduction"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    List<Student> selectAll();

    // 根据ID查询学生信息
    @Select("SELECT id, user_id, real_name, gender, birthday, id_card, university, major, " +
            "education, graduation_time, political_status, hometown, current_city, " +
            "job_intention, job_type, salary_expectation, self_introduction, create_time, update_time " +
            "FROM student_info WHERE id = #{id}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "user", column = "user_id",
                    one = @One(select = "edu.gdkm.dao.UserDAO.selectById")),
            @Result(property = "realName", column = "real_name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "idCard", column = "id_card"),
            @Result(property = "university", column = "university"),
            @Result(property = "major", column = "major"),
            @Result(property = "education", column = "education"),
            @Result(property = "graduationTime", column = "graduation_time"),
            @Result(property = "politicalStatus", column = "political_status"),
            @Result(property = "hometown", column = "hometown"),
            @Result(property = "currentCity", column = "current_city"),
            @Result(property = "jobIntention", column = "job_intention"),
            @Result(property = "jobType", column = "job_type"),
            @Result(property = "salaryExpectation", column = "salary_expectation"),
            @Result(property = "selfIntroduction", column = "self_introduction"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    Student selectById(Long id);

    // 根据用户ID查询学生信息
    @Select("SELECT id, user_id, real_name, gender, birthday, id_card, university, major, " +
            "education, graduation_time, political_status, hometown, current_city, " +
            "job_intention, job_type, salary_expectation, self_introduction, create_time, update_time " +
            "FROM student_info WHERE user_id = #{userId}")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "user", column = "user_id",
                    one = @One(select = "edu.gdkm.dao.UserDAO.selectById")),
            @Result(property = "realName", column = "real_name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "idCard", column = "id_card"),
            @Result(property = "university", column = "university"),
            @Result(property = "major", column = "major"),
            @Result(property = "education", column = "education"),
            @Result(property = "graduationTime", column = "graduation_time"),
            @Result(property = "politicalStatus", column = "political_status"),
            @Result(property = "hometown", column = "hometown"),
            @Result(property = "currentCity", column = "current_city"),
            @Result(property = "jobIntention", column = "job_intention"),
            @Result(property = "jobType", column = "job_type"),
            @Result(property = "salaryExpectation", column = "salary_expectation"),
            @Result(property = "selfIntroduction", column = "self_introduction"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    Student selectByUserId(Long userId);

    // 根据真实姓名查询学生信息
    @Select("SELECT id, user_id, real_name, gender, birthday, id_card, university, major, " +
            "education, graduation_time, political_status, hometown, current_city, " +
            "job_intention, job_type, salary_expectation, self_introduction, create_time, update_time " +
            "FROM student_info WHERE real_name LIKE CONCAT('%', #{realName}, '%')")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "user", column = "user_id",
                    one = @One(select = "edu.gdkm.dao.UserDAO.selectById")),
            @Result(property = "realName", column = "real_name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "idCard", column = "id_card"),
            @Result(property = "university", column = "university"),
            @Result(property = "major", column = "major"),
            @Result(property = "education", column = "education"),
            @Result(property = "graduationTime", column = "graduation_time"),
            @Result(property = "politicalStatus", column = "political_status"),
            @Result(property = "hometown", column = "hometown"),
            @Result(property = "currentCity", column = "current_city"),
            @Result(property = "jobIntention", column = "job_intention"),
            @Result(property = "jobType", column = "job_type"),
            @Result(property = "salaryExpectation", column = "salary_expectation"),
            @Result(property = "selfIntroduction", column = "self_introduction"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    List<Student> selectByRealName(String realName);

    // 根据学校查询学生信息
    @Select("SELECT id, user_id, real_name, gender, birthday, id_card, university, major, " +
            "education, graduation_time, political_status, hometown, current_city, " +
            "job_intention, job_type, salary_expectation, self_introduction, create_time, update_time " +
            "FROM student_info WHERE university LIKE CONCAT('%', #{university}, '%')")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "user", column = "user_id",
                    one = @One(select = "edu.gdkm.dao.UserDAO.selectById")),
            @Result(property = "realName", column = "real_name"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "birthday", column = "birthday"),
            @Result(property = "idCard", column = "id_card"),
            @Result(property = "university", column = "university"),
            @Result(property = "major", column = "major"),
            @Result(property = "education", column = "education"),
            @Result(property = "graduationTime", column = "graduation_time"),
            @Result(property = "politicalStatus", column = "political_status"),
            @Result(property = "hometown", column = "hometown"),
            @Result(property = "currentCity", column = "current_city"),
            @Result(property = "jobIntention", column = "job_intention"),
            @Result(property = "jobType", column = "job_type"),
            @Result(property = "salaryExpectation", column = "salary_expectation"),
            @Result(property = "selfIntroduction", column = "self_introduction"),
            @Result(property = "createTime", column = "create_time"),
            @Result(property = "updateTime", column = "update_time")
    })
    List<Student> selectByUniversity(String university);
}
